class BG3HUDLayoutBase extends Object
	abstract;

//array to UI elements
var array<BG3UIElement> elements;

//store objects the mouse cursor is currently over
var array<BG3UIElement> mouseoverelements;

//enabled or not
var bool bEnabled;

//show mouse?
var bool bShowMouse;

//Store a reference to owner HUD
var BG3HUD hud;

//name, different from the base Object class's Name field
var string sLayoutName;

//Draw, called from BG3HUD
simulated function Draw(Canvas drawonthis, BG3HUD ahud)
{
	//local variable must be first
	local int i;
	local int j;
	if(ahud != none)
	{
		hud = ahud;
	}
	//if enabled, draw UI elements and cursor if we want to show it, order is important, we always want cursor on top
	if(bEnabled)
	{
		if(elements.Length > 0)
		{
			for (i = 0; i < elements.Length; i++)
			{
				elements[i].Draw(drawonthis);
			}
		}
		if(bShowMouse)
		{
			if(ahud != none) DrawMouse(drawonthis);
		}
	}
	//notify mouseover events
	if(mouseoverelements.Length > 0)
	{
		for(j=0;j<mouseoverelements.Length;j++)
		{
			mouseoverelements[j].OnMouseOver();
		}
	}
}

//add element
simulated function AddElement(BG3UIElement element)
{
	local int i;
	//only add if we dont have it already
	for (i = 0; i < elements.Length; i++)
	{
		if(elements[i] == element)
		{
			return;
		}
	}
	elements.AddItem(element);
}

simulated function DrawMouse(Canvas drawonthis)
{
	local IntPoint rendermousepos;
	local int i;
	local int j;
	if(drawonthis != none)
	{
		if(hud != none)
		{
			//get mouse coordinates
			if(BG3PlayerController(hud.PlayerOwner) != none)
			{
				rendermousepos = BG3PlayerController(hud.PlayerOwner).CurrentMousePosition;
				//need to clamp it to the sides of the screen
				rendermousepos.X = Clamp(rendermousepos.X,0,drawonthis.ClipX-hud.cursorsizeX/2);
				rendermousepos.Y = Clamp(rendermousepos.Y,0,drawonthis.ClipY-hud.cursorsizeY/2);
			}
			//do the drawing
			drawonthis.SetPos(rendermousepos.X,rendermousepos.Y);
			drawonthis.DrawTile(hud.cursortex,hud.cursorsizeX,hud.cursorsizeY,0,0,64,64,,false);

			//solve which object is the cursor over
			if(elements.Length > 0)
			{
				//clear all mouseoverlements first, then add current ones
				if(mouseoverelements.Length > 0)
				{
					for(j = 0; j < mouseoverelements.Length; j++)
					{
						//signal element that it is going out of mouseover
						mouseoverelements[j].OnMouseOut();
						mouseoverelements.RemoveItem(mouseoverelements[j]);
					}
				}
				for(i = 0; i < elements.Length; i++)
				{
					if(rendermousepos.X > elements[i].ScreenPosX && rendermousepos.X < elements[i].ScreenPosX+elements[i].SizeX)
					{
						if(rendermousepos.Y > elements[i].ScreenPosY && rendermousepos.Y < elements[i].ScreenPosY+elements[i].SizeY)
						{
							mouseoverelements.AddItem(elements[i]);
						}
					}
				}
			}
		}
	}


}

defaultproperties
{
	
}